import request from '@/utils/request'

/**
 * 题目管理API
 */
export const questionApi = {
  /**
   * 分页查询题目列表
   */
  listQuestions(page = 1, size = 10, category = null, type = null) {
    const params = { page, size }
    if (category) params.category = category
    if (type) params.type = type
    return request({
      url: '/api/admin/questions',
      method: 'get',
      params
    })
  },

  /**
   * 根据ID获取题目
   */
  getQuestionById(id) {
    return request({
      url: `/api/admin/questions/${id}`,
      method: 'get'
    })
  },

  /**
   * 创建题目
   */
  createQuestion(question) {
    return request({
      url: '/api/admin/questions',
      method: 'post',
      data: question
    })
  },

  /**
   * 更新题目
   */
  updateQuestion(id, question) {
    return request({
      url: `/api/admin/questions/${id}`,
      method: 'put',
      data: question
    })
  },

  /**
   * 删除题目
   */
  deleteQuestion(id) {
    return request({
      url: `/api/admin/questions/${id}`,
      method: 'delete'
    })
  },

  /**
   * 批量删除题目
   */
  batchDeleteQuestions(ids) {
    return request({
      url: '/api/admin/questions/batch',
      method: 'delete',
      data: ids
    })
  },

  /**
   * 批量导入题目
   */
  importQuestions(file) {
    const formData = new FormData()
    formData.append('file', file)
    return request({
      url: '/api/admin/quiz/import',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  /**
   * 下载导入模板
   */
  downloadTemplate() {
    return request({
      url: '/api/admin/quiz/template',
      method: 'get'
    })
  }
}

